import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/model/note_model.dart';
import 'commit_headerView.dart';
import 'commit_cell.dart';

class NoteCenterView extends StatefulWidget {
  final NoteModel model;

  const NoteCenterView({Key? key, required this.model}) : super(key: key);

  @override
  _NoteCenterViewState createState() => _NoteCenterViewState();
}

class _NoteCenterViewState extends State<NoteCenterView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(left: 15, right: 15, bottom: 15),
      child: Column(
        children: [
          _noteWidget(),
          _timeWidget(),
          _commitWidget()
        ],
      ),
    );
  }

  /// 笔记列表
  Widget _noteWidget() {
    return ListView.builder(
        shrinkWrap: true,

        ///禁用滑动事件
        physics: NeverScrollableScrollPhysics(),
        itemCount: widget.model.contents!.length + 1,
        itemBuilder: (BuildContext context, int index) {
          if (index == 0) {
            return Text(widget.model.title!,
                strutStyle:
                    StrutStyle(forceStrutHeight: true, height: 1, leading: 1),
                style: TextStyle(
                    fontSize: 17,
                    color: Colors.black,
                    fontWeight: FontWeight.bold));
          } else {
            return Text(
                int.parse(widget.model.contents![index - 1].id!) > 0
                    ? '#' + widget.model.contents![index - 1].c!
                    : widget.model.contents![index - 1].c!,
                strutStyle:
                    StrutStyle(forceStrutHeight: true, height: 1, leading: 1),
                style: TextStyle(
                  fontSize: 15,
                  color: int.parse(widget.model.contents![index - 1].id!) > 0
                      ? Color.fromRGBO(94, 146, 140, 1)
                      : HexColor(widget.model.contents![index - 1].color!),
                ));
          }
        });
  }

  /// 时间 收藏点赞
  Widget _timeWidget() {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(left: 0, right: 0, top: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(widget.model.publishtime!,
              style: TextStyle(
                  fontSize: 13,
                  color: AppColors.qianTextColor,
                  fontWeight: FontWeight.w400)),
          Text(
              widget.model.favo_count_text! +
                  '次收藏' +
                  ' ' +
                  widget.model.like_count_text! +
                  '次赞',
              style: TextStyle(
                  fontSize: 13,
                  color: AppColors.qianTextColor,
                  fontWeight: FontWeight.w400)),
        ],
      ),
    );
  }

  /// 评论列表
  Widget _commitWidget() {
    return ListView.builder(
        shrinkWrap: true,

        ///禁用滑动事件
        physics: NeverScrollableScrollPhysics(),
        itemCount: widget.model.cs!.length + 1,
        itemBuilder: (BuildContext context, int index) {
          if (index == 0) {
            return CommitHeaderView();
          } else {
            return CommitCell(
              model: widget.model.cs![index - 1],
              commotList: widget.model.cs!,
              index: index,
            );
          }
        });
  }
}
